/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.scrumpmt.web;

import java.util.Date;
import java.util.logging.Level;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;
import org.scrumpmt.domain.Sprint;
import org.scrumpmt.ejb.SprintFacade;

/**
 *
 * @author aljiru
 */
@ManagedBean
@RequestScoped
public class ListadoSprintBean extends BasicBean {

    @EJB
    private SprintFacade sprintFacade;
    @ManagedProperty(value = "#{param.id}")
    private String id;
    @ManagedProperty(value = "#{param.sprint}")
    private String idsp;
    private String idsprint;
    FacesContext context = FacesContext.getCurrentInstance();
    ProductoSeleccionadoBean bean = (ProductoSeleccionadoBean) context.getApplication().
            evaluateExpressionGet(context, "#{productoSeleccionadoBean}", ProductoSeleccionadoBean.class);

    /**
     * Creates a new instance of EditarProductoBean
     */
    public ListadoSprintBean() {
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public ProductoSeleccionadoBean getBean() {
        return bean;
    }

    public void setBean(ProductoSeleccionadoBean bean) {
        this.bean = bean;
    }

    public String getIdsprint() {
        return idsprint;
    }

    public void setIdsprint(String idsprint) {
        this.idsprint = idsprint;
    }

    public String getIdsp() {
        return idsp;
    }

    public void setIdsp(String idsp) {
        this.idsp = idsp;
    }

    @PostConstruct
    public void cargaProducto() {
        if (id != null && !id.equals("")) {
             
            bean.setProductoActual(id);
            Sprint sprint = sprintFacade.findSprintActualProyecto(id, new Date());
            if (sprint == null) {
                bean.setSprintActual("-1");
            } else {
                idsprint = String.valueOf(sprint.getId());
                bean.setSprintActual(idsprint);
            }

            log.log(Level.INFO, "Producto:{0} - Sprint: {1}", new Object[]{id, idsprint});
        }
        if (idsp != null && !idsp.equals("") && !idsp.equals("0")) {
            bean.setSprintActual(idsp);
            log.log(Level.INFO, "Sprint: {0}", idsp);
        }
    }
    
    
}
